﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using PCI1616DLL;

namespace OCR.Function
{
    class PCI1616_Initial
    {
        public static int hDevice;
        public static int iResult, i;
        public static byte[] DLLVer = new byte[60];
        public static int cardNum = 0;
        public static String strTemp;
        public static int cardId = 0;
        public static bool bInitial = false;

        static void ShowError(int Result)
        {
            byte[] message = new byte[60];
            int error;
            string str;

            if (Result != 0)
            {
                error = XCDotNETAPI_PCI1616.GetErrorMessage(Result, message);
                str = System.Text.Encoding.Default.GetString(message);
                Console.WriteLine("错误信息：" + str);
            }
        }
        public static void PCI1616_InitialClass()
        {
            iResult = XCDotNETAPI_PCI1616.GetDLLVersion(DLLVer);
            if (iResult == 0)
            {

            }
            else
            {
                MessageBox.Show("確認DIO卡是否安裝完成？");
                ShowError(iResult);
            }
            //Console.WriteLine("DLL版本号为：" + Encoding.Default.GetString(DLLVer).Replace("\0", ""));

            cardId = 0;
            iResult = XCDotNETAPI_PCI1616.OpenDevice(cardId, ref hDevice);
            if (iResult == 0)
            {

            }
            else
            {
                MessageBox.Show("確認DIO卡是否安裝完成？");
                ShowError(iResult);
            }
        }
        public static void PCI1616_Close()
        {
            iResult = XCDotNETAPI_PCI1616.CloseDevice(hDevice);
            if (iResult == 0)
            {

            }
            else
            {
                ShowError(iResult);
            }
        }
    }
}
